<template>
  <div class="stayhome" v-if="datalist[0]">
    <!-- banner轮播 -->
    <swiper :gigodata ="{
            loop: true,
            pagination: {
              el: '.swiper-pagination',
              //可点击分页进行跳转
              clickable: true,
            },
            autoplay: {
              delay: 2500,
              disableOnInteraction: false,
            }
          }"
          gigoclass="gigobanner"
          :key="datalist.length">
      <div class="swiper-slide" v-for="data in datalist[0].moduleContent.banners" :key="data.id">
        <img class="banner" :src="data.bannerImgSrc">
      </div>
    </swiper>

    <!-- 创新Title -->
    <div class="titlemodule">
      <h4>{{datalist[1].moduleName}}</h4>
      <p>{{datalist[1].moduleDescription}}</p>
    </div>

    <!-- 创新轮播 -->
    <swiper :gigodata ="{slidesPerView:3}" gigoclass="gigoproduc" :key="datalist[1].length">
      <div class="swiper-slide produccontent" v-for="data in datalist[1].moduleContent.products" :key="data.id" @click="handleDetail(data.productId,data)">
        <img :src="data.productImg">
        <p class="name">{{data.productTitle}}</p>
        <p class="money">￥{{data.sellPrice}}<span>{{data.originalPrice === data.sellPrice?'':'￥'+data.originalPrice}}</span></p>
      </div>
    </swiper>
   <div class="look" @click="handleClick(10704)">查看全部<span>&rsaquo;</span></div>

    <!-- 杂物Title -->
    <div class="titlemodule">
      <h4>{{datalist[2].moduleName}}</h4>
      <p>{{datalist[2].moduleDescription}}</p>
    </div>

    <!-- 杂物List -->
    <ul class="productslist">
      <li v-for="data in datalist[2].moduleContent.products" :key="data.parentProductId" @click="handleDetail(data.productId,data)">
        <img :src="data.productImg">
        <div class="anysting">
          <p class="anyname">{{data.productName}}</p>
          <p class="anymoney">￥{{data.sellPrice}}<span>{{data.originalPrice === data.sellPrice?'':'￥'+data.originalPrice}}</span></p>
        </div>
      </li>
    </ul>
    <div class="look" @click="handleClick(11427)">查看全部<span>&rsaquo;</span></div>

    <!-- 光影艺术Title -->
    <div class="titlemodule">
      <h4>{{datalist[3].moduleName}}</h4>
      <p>{{datalist[3].moduleDescription}}</p>
    </div>

    <!-- 光影艺术List -->
    <ul class="productslist">
      <li v-for="data in datalist[3].moduleContent.products" :key="data.parentProductId" @click="handleDetail(data.productId,data)">
        <img :src="data.productImg">
        <div class="anysting">
          <p class="anyname">{{data.productName}}</p>
          <p class="anymoney">￥{{data.sellPrice}}<span>{{data.originalPrice === data.sellPrice?'':'￥'+data.originalPrice}}</span></p>
        </div>
      </li>
    </ul>
    <div class="look" @click="handleClick(12141)">查看全部<span>&rsaquo;</span></div>

    <!-- 到底警告 -->
    <div class="foot">
      <p>已经到底了</p>
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
import swiper from '@/components/Swiper'
import axios from 'axios'
export default {
  data () {
    return {
      datalist: []
    }
  },
  methods: {
    handleClick (id) {
      this.$router.push(`/productGroup/${id}`) // 切换页面
    },
    handleDetail (goodsId, goods) {
      localStorage.setItem('goods', JSON.stringify(goods))
      this.$router.push(`/detail/${goodsId}`)
    }
  },
  components: {
    swiper
  },
  mounted () {
    axios.get('/v2/page?pageId=1&tabId=10006&currentPage=1&pageSize=8&_=1583323544126').then(res => {
      this.datalist = res.data.data.modules
      console.log(this.datalist)
    })
  }
}
</script>

<style lang="scss" scoped>
  .stayhome{
    margin-top: 3px;
    background-color: #F5F5F5;
    .gigobanner{
      height: 240px;
      .banner{
        height: 100%;
      }
    }
    .titlemodule{
      margin-top: 20px;
      text-align: center;
      background-color: #fff;
      h4{
        padding-top: 30px;
        padding-bottom: 20px;
      }
      p{
        font-size: 12px;
        color: #666;
        padding-bottom: 14px;
      }
    }
    .gigoproduc{
      background-color: #fff;
      .produccontent{
        display: flex;
        flex-direction:column;
        align-items: center;
        img{
          height: 84px;
        }
        .name{
          font-size: 12px;
          color: #999;
          width: 86px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .money{
          color: #333;
          font-size: 12px;
          span{
            text-decoration:line-through;
            color: #999;
            margin-left: 3px;
          }
        }
      }
    }
    .look{
      background-color: #fff;
      text-align: center;
      font-size: 12px;
      color: #333;
      padding-top: 16px;
      padding-bottom: 16px;
      span{
        font-size: 16px;
        margin-left: 2px;
      }
    }
    .productslist{
      width: 100%;
      background-color: #fff;
      display: flex;
      flex-wrap: wrap;
      li{
        width: 50%;
        height: 260px;
        list-style: none;
        border: 1px solid rgb(240, 240, 240);
        border-left: none;
        box-sizing: border-box;
        img{
          width: 100%;
        }
        .anysting{
          padding-left: 20px;
          padding-right: 20px;
          .anyname{
          font-size: 13px;
          color: #999;
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .anymoney{
          font-size: 14px;
          span{
            text-decoration:line-through;
            color: #999;
            margin-left: 3px;
          }
        }
        }
      }
    }
    .hotgood{
      width: 100%;
      display: flex;
      background-color: #fff;
      justify-content: space-evenly;
      li{
        width: 20%;
        list-style: none;
        img{
          width: 100%;
        }
      }
    }
    .foot{
      background-color: #fff;
      padding-bottom: 80px;
      padding-top: 40px;
      font-size: 12px;
      text-align: center;
    }
  }
</style>
